package com.swlz.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.swlz.service.UserService;
import com.swlz.service.impl.UserServiceImpl;

@WebServlet("/check-name.let")
public class CheckNameServlet extends HttpServlet {
	
	private UserService userService = new UserServiceImpl();

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userName = request.getParameter("userName");
		boolean valid = !userService.existsUserName(userName);
		response.setContentType("text/json;charset=UTF-8");
		response.getWriter().print("{\"valid\":"+valid+"}");
		response.flushBuffer();
	}
}